<template>
  <div class="login-container">
    <!-- 左侧内容区域 -->
    <div class="left-content">
      <!-- 主标题区域 -->
      <div class="hero-section">
        <h1 class="main-title">
          <span class="title-primary">KiKi Ai</span>
        </h1>
        <p class="title-subtitle">小朋友们最好的AI学习伙伴，让学习更智能，让成长更精彩</p>
      </div>

      <!-- 功能介绍板块 -->
      <div class="features-section">
        <!-- 板块2：聚合顶尖模型 -->
        <div class="feature-block">
          <div class="feature-content">
            <h3 class="feature-title">一站式聚合全球顶尖AI学习大模型</h3>
            <p class="feature-description">
              为教学注入无限动力，为每个学习问题提供最佳解决方案
            </p>
            
            <!-- AI专家模型展示 -->
            <div class="ai-models-section">
              <div class="models-grid">
                <div class="model-card">
                  <div class="model-icon bg-blue-500">
                    <i class="fas fa-robot"></i>
                  </div>
                  <div class="model-info">
                    <h5 class="model-name">Gemini 2.5 Pro (博学的大学教授)</h5>
                    <p class="model-expertise">知识渊博，逻辑严密。适合深度学术探讨、复杂问题推理。</p>
                  </div>
                </div>
                
                <div class="model-card">
                  <div class="model-icon bg-purple-500">
                    <i class="fas fa-lightbulb"></i>
                  </div>
                  <div class="model-info">
                    <h5 class="model-name">GPT-4o (全能的常春藤导师)</h5>
                    <p class="model-expertise">反应迅捷，善于沟通。精通多模态对话，是你的全能日常助手。</p>
                  </div>
                </div>
                
                <div class="model-card">
                  <div class="model-icon bg-green-500">
                    <i class="fas fa-code"></i>
                  </div>
                  <div class="model-info">
                    <h5 class="model-name">Claude 3 Opus (富有创造力的文学家)</h5>
                    <p class="model-expertise">文笔优美，思想深刻。擅长长文写作、创意构思和伦理分析。</p>
                  </div>
                </div>
                
                <div class="model-card">
                  <div class="model-icon bg-orange-500">
                    <i class="fas fa-language"></i>
                  </div>
                  <div class="model-info">
                    <h5 class="model-name">DeepSeek-V3 (严谨的科研学者)</h5>
                    <p class="model-expertise">代码与逻辑大师。专注于编程、数学和需要精确推理的任务。</p>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 右侧登录区域 -->
    <div class="right-content">
      <div class="login-card">
        <div class="login-header">
          <div class="logo">logo</div>
          <h1 class="login-title">登录/注册</h1>
          <p class="login-subtitle">请使用手机号快捷登录/注册</p>
        </div>
        
        <form @submit.prevent="handleLogin" class="login-form">
          <!-- 表单内容保持不变 -->
          <div class="form-group">
            <label for="phone" class="form-label">手机号</label>
            <div class="input-wrapper">
              <i class="fas fa-phone input-icon"></i>
              <input 
                v-model="loginForm.phone"
                type="tel" 
                id="phone" 
                class="form-input" 
                placeholder="请输入手机号"
              >
            </div>
          </div>
          
          <div class="form-group">
            <label for="verificationCode" class="form-label">验证码</label>
            <div class="verification-wrapper">
              <div class="input-wrapper">
                <i class="fas fa-shield-alt input-icon"></i>
                <input 
                  v-model="loginForm.verificationCode"
                  type="text" 
                  id="verificationCode" 
                  class="form-input" 
                  placeholder="请输入验证码"
                >
              </div>
              <button 
                type="button" 
                @click="getVerificationCode"
                :disabled="countdown > 0"
                class="verification-button"
              >
                {{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
              </button>
            </div>
          </div>
          
          <div class="agreement">
            登录即表示同意 <a href="#" class="agreement-link">用户协议</a> 和 <a href="#" class="agreement-link">隐私政策</a>
          </div>
          
          <button 
            type="submit" 
            :disabled="isLoading"
            class="login-button"
          >
            <span v-if="isLoading" class="button-content">
              <i class="fas fa-spinner fa-spin"></i>
              登录中...
            </span>
            <span v-else class="button-content">登录/注册</span>
          </button>
        </form>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// JavaScript 部分保持不变
import { ref, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 表单数据
const loginForm = ref({
  phone: '',
  verificationCode: ''
})

// 状态管理
const isLoading = ref(false)
const countdown = ref(0)
let timer: NodeJS.Timeout | null = null

// 获取验证码
const getVerificationCode = () => {
  const phone = loginForm.value.phone.trim()
  if (!/^1[3-9]\d{9}$/.test(phone)) {
    alert('请输入正确的手机号')
    return
  }
  
  startCountdown()
  console.log('发送验证码到:', phone)
}

// 开始倒计时
const startCountdown = () => {
  countdown.value = 60
  timer = setInterval(() => {
    countdown.value--
    if (countdown.value <= 0) {
      clearInterval(timer!)
      timer = null
    }
  }, 1000)
}

// 登录处理
const handleLogin = async () => {
  const phone = loginForm.value.phone.trim()
  const code = loginForm.value.verificationCode.trim()
  
  // 特殊登录：admin + 123456 直接跳转到首页
  if (phone === 'admin' && code === '123456') {
    isLoading.value = true
    
    try {
      await new Promise(resolve => setTimeout(resolve, 500))
      console.log('管理员登录成功')
      router.push('/')
    } catch (error) {
      console.error('登录失败:', error)
      alert('登录失败，请重试')
    } finally {
      isLoading.value = false
    }
    return
  }
  
  // 原有的手机号验证逻辑
  if (!/^1[3-9]\d{9}$/.test(phone)) {
    alert('请输入正确的手机号')
    return
  }
  
  if (!/^\d{6}$/.test(code)) {
    alert('请输入6位验证码')
    return
  }
  
  isLoading.value = true
  
  try {
    await new Promise(resolve => setTimeout(resolve, 1500))
    console.log('登录信息:', loginForm.value)
    router.push('/')
  } catch (error) {
    console.error('登录失败:', error)
    alert('登录失败，请检查手机号和验证码')
  } finally {
    isLoading.value = false
  }
}

// 组件卸载时清理定时器
onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
/* 基础布局 */
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #f0f9ff 0%, #ffffff 50%, #f8fafc 100%);
  display: flex;
  overflow: hidden;
}

.left-content {
  width: 60%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 2.5rem;
  overflow-y: auto;
  min-height: 100vh;
  background-color: rgb(248 250 252 / var(--tw-bg-opacity, 1));
}

.right-content {
  width: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow-y: auto;
}

/* Hero区域 - 居中排列 */
.hero-section {
  margin-bottom: 2rem;
  text-align: center;
}

.main-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  line-height: 1.1;
}

.title-primary {
  background: rgb(79 70 229 / var(--tw-bg-opacity, 1));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: bold;
  font-size: 4rem;
}

.title-subtitle {
  font-size: 1.125rem;
  color: #6b7280;
  font-weight: 400;
  margin: 0;
}

/* 功能介绍区域 */
.features-section {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.feature-block {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
}

.feature-content {
  flex: 1;
  text-align: center;
}

.feature-title {
  font-size: 1.375rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 0.5rem 0;
  line-height: 1.3;
}

.feature-description {
  font-size: 0.9375rem;
  color: #4b5563;
  line-height: 1.5;
  margin: 0;
}

/* AI专家模型区域 */
.ai-models-section {
  margin-top: 1.25rem;
  max-width: 80%;
  margin-left: auto;
  margin-right: auto;
}

.models-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.model-card {
  background: white;
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.model-card:hover {
  border-color: #4F46E5;
  transform: scale(1.05);
}

.model-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.model-icon i {
  font-size: 1.25rem;
  color: white;
}

.model-info {
  flex: 1;
  text-align: left;
}

.model-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 0.25rem 0;
  text-align: left;
}

.model-expertise {
  font-size: 0.875rem;
  color: #6b7280;
  margin: 0;
  line-height: 1.4;
  text-align: left;
}

/* 登录表单样式 */
.login-card {
  width: 100%;
  max-width: 26rem;
  background-color: white;
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  padding: 1.75rem;
}

.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.logo {
  font-family: 'Pacifico', cursive;
  font-size: 1.75rem;
  color: #3b82f6;
  margin-bottom: 0.5rem;
}

.login-title {
  font-size: 1.375rem;
  font-weight: 600;
  color: #1f2937;
}

.login-subtitle {
  color: #6b7280;
  margin-top: 0.5rem;
  font-size: 0.9375rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.25rem;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  pointer-events: none;
}

.form-input {
  width: 100%;
  padding: 0.75rem 0.75rem 0.75rem 2.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.verification-wrapper {
  display: flex;
  gap: 0.75rem;
}

.verification-button {
  padding: 0.75rem 1rem;
  background-color: rgb(79 70 229 / var(--tw-bg-opacity, 1));
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-size: 0.875rem;
}

.verification-button:hover:not(:disabled) {
  background-color: rgb(79 70 229 / var(--tw-bg-opacity, 1));
}

.verification-button:disabled {
  background-color: #e5e7eb;
  cursor: not-allowed;
}

.agreement {
  font-size: 0.75rem;
  color: #6b7280;
  text-align: center;
}

.agreement-link {
  color: #3b82f6;
  text-decoration: none;
}

.agreement-link:hover {
  text-decoration: underline;
}

/* 登录按钮样式 */
.login-button {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgb(79 70 229 / var(--tw-bg-opacity, 1));
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.login-button:hover:not(:disabled) {
  background: rgb(79 70 229 / var(--tw-bg-opacity, 1));
  transform: translateY(-1px);
  box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.15);
}

.login-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.button-content {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.button-content i {
  margin-right: 0.5rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .left-content {
    width: 50%;
    padding: 2.5rem 2rem;
  }
  
  .right-content {
    width: 50%;
    padding: 1.5rem;
  }
  
  .main-title {
    font-size: 2.5rem;
  }
}

@media (max-width: 768px) {
  .login-container {
    flex-direction: column;
    overflow-y: auto;
  }
  
  .left-content {
    width: 100%;
    min-height: auto;
    padding: 1.5rem 1rem;
    flex: 0 0 auto;
  }
  
  .right-content {
    width: 100%;
    min-height: auto;
    padding: 1.5rem 1rem;
    flex: 0 0 auto;
  }
  
  .main-title {
    font-size: 2rem;
  }
  
  .title-subtitle {
    font-size: 1rem;
  }
  
  .feature-block {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }
  
  .feature-title {
    font-size: 1.25rem;
  }
  
  .feature-description {
    font-size: 0.875rem;
  }
  
  .models-grid {
    grid-template-columns: 1fr;
    gap: 0.875rem;
  }
  
  .model-card {
    padding: 1rem;
  }
  
  .login-card {
    padding: 1.5rem;
  }
}

@media (max-width: 480px) {
  .left-content {
    padding: 1rem 0.75rem;
  }
  
  .right-content {
    padding: 1rem 0.75rem;
  }
  
  .main-title {
    font-size: 1.75rem;
  }
  
  .feature-title {
    font-size: 1.125rem;
  }
  
  .feature-description {
    font-size: 0.8125rem;
  }
  
  .model-card {
    padding: 0.875rem;
  }
  
  .login-card {
    padding: 1.25rem;
  }
  
  .verification-button {
    padding: 0.75rem 0.75rem;
    font-size: 0.8125rem;
  }
}

@media (max-width: 360px) {
  .left-content {
    padding: 0.75rem 0.5rem;
  }
  
  .right-content {
    padding: 0.75rem 0.5rem;
  }
  
  .main-title {
    font-size: 1.5rem;
  }
  
  .models-grid {
    gap: 0.75rem;
  }
  
  .login-card {
    padding: 1rem;
  }
}
</style>